package org.management.system.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.management.base.data.Result;
import org.management.config.shiro.manager.TokenManager;
import org.management.system.entity.UserEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;

/**
 * 功能描述
 *
 * @author jy
 * @date 2019/3/15
 * @description
 * @project management
 */
@Api("通用模块")
@RestController
public class CommonController {

    @PostMapping(value = "login")
    @ApiOperation("用户登录")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "name",value = "用户登录名称",required = true),
        @ApiImplicitParam(name = "password",value = "用户登录密码",required = true)
    })
    public Result login(@NotEmpty(message = "登录名称不能为空") String name,
                        @NotEmpty(message = "用户密码不能为空") String password) {
        UserEntity userEntity = new UserEntity();
        userEntity.setLoginName(name);
        userEntity.setPassword(password);
        TokenManager.login(userEntity,false);
        return Result.success("登录成功");
    }

    @PostMapping(value = "logout")
    @ApiOperation("当前用户退出")
    public Result logout() {
        TokenManager.logout();
        return Result.success("退出成功");
    }
}
